

#import "UIViewController+TPUtility.h"
#import <objc/runtime.h>

@implementation UIViewController (TPUtility)

////runtime 设置 属性
//-(void)setAlertVC_HUD_loading:(TPAlertViewController *)alertVC_HUD_loading{
//    objc_setAssociatedObject(self, &alertVC_HUD_loadingKey, alertVC_HUD_loading, OBJC_ASSOCIATION_RETAIN);
//}
//-(TPAlertViewController *)alertVC_HUD_loading{
//    return objc_getAssociatedObject(self, &alertVC_HUD_loadingKey);
//}



#pragma mark - getViewController

-(UIViewController *)getViewController:(Class )viewControllerClass {
    for (UIViewController * vc in self.navigationController.viewControllers.reverseObjectEnumerator) {
        if ([vc isMemberOfClass:viewControllerClass]) {
            return vc;
        }
    }
    
    return nil;
}
//递归获取 全部 某类VC
-(NSMutableArray <UIViewController *> *)getChildViewControllersWithClass:(Class )viewControllerClass {
    NSMutableArray <UIViewController *> * vcs = [NSMutableArray new];
    for (UIViewController * vc in self.childViewControllers) {
        if ([vc isMemberOfClass:viewControllerClass]) {
            [vcs addObject: vc];
        }else{
            [vcs addObjectsFromArray: [vc getChildViewControllersWithClass:viewControllerClass]];
            
        }
    }
    
    return vcs;
}

@end
